﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SpeechLib;
using System.Speech.Recognition;
using System.Speech.Synthesis;

namespace TextToSpeech
{
    public partial class Form1 : Form
    {
        SpeechRecognizer rec = new SpeechRecognizer();
  
        public Form1()
        {
            InitializeComponent();
            rec.SpeechRecognized += rec_SpeechRecognized;
        }

        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            label1.Text = e.Result.Text;
            SpeechSynthesizer sp = new SpeechSynthesizer();
            sp.Speak("You said: " + e.Result.Text);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var c = new Choices();
            for (var i = 0; i <= 200; i++)
                c.Add(i.ToString());
            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;
        }

    }
}
